# coding: utf-8

from fralog.FraLog import Fralog
import UploadSurvey as us
import pandas

LOG = Fralog().getFileLog()


class DataExport(object):
    """
    该类主要负责导出问卷原始数据
    """

    def __init__(self):
        super(DataExport, self).__init__()

    def export_data_with_code(self, code):
        """
        根据问卷的code导出问卷
        :param code: 
        :return: 
        """
        db, client = us.get_db_client()
        rows = db.responses_collection.find({'code': code})

        if rows is None:
            return None

        rets = []
        for row in rows:
            row.pop('_id')
            rets.append(row)

        df = pandas.DataFrame(rets)
        df.to_excel(code + '.xlsx')


if __name__ == '__main__':
    de = DataExport()
    de.export_data_with_code('v28')
